package me.ingxin.android.badge

import android.view.View
import androidx.annotation.ColorInt

/**
 * Created by ingxin on 2022/12/20
 * 数字角标
 */
class NumberBadge private constructor(
    private val badgeDrawable: BadgeDrawable,
    anchor: View,
    gravity: Gravity
) : Badge(badgeDrawable, anchor, gravity) {

    /**
     * 设置角标数
     */
    fun setNumb(number: Int) {
        badgeDrawable.number = number
        update()
    }

    /**
     * 获取角标数
     */
    fun getNumber(): Int {
        return badgeDrawable.number
    }

    class Builder : BadgeBuilder<Builder>() {

        /**
         * 设置最大角标数，大于最大值时用+表示
         */
        fun setMaxNumber(number: Int): Builder {
            badgeDrawable.maxNumber = number
            return this
        }

        /**
         * 设置角标文本颜色
         */
        fun setTextColor(@ColorInt color: Int): Builder {
            badgeDrawable.textColor = color
            return this
        }

        /**
         * 设置角标文本颜色
         */
        fun setTextSize(size: Int): Builder {
            badgeDrawable.textSize = size
            return this
        }

        /**
         * 角标文本是否加粗，默认加粗
         */
        fun setTextBold(bold: Boolean): Builder {
            badgeDrawable.textBold = bold
            return this
        }

        /**
         * 角标文本过长时，膨胀成圆角矩形时，文本水平方向左右padding，圆形时忽略
         */
        fun setRoundPaddingHorizontal(padding: Int): Builder {
            badgeDrawable.roundPaddingHorizontal = padding
            return this
        }

        /**
         * 垂直方向左右padding，见[setRoundPaddingHorizontal]
         */
        fun setRoundPaddingVertical(padding: Int): Builder {
            badgeDrawable.roundPaddingVertical = padding
            return this
        }

        /**
         * 当角标为圆形时，文本的padding值
         */
        fun setCirclePadding(padding: Int): Builder {
            badgeDrawable.circlePadding = padding
            return this
        }

        fun build(anchor: View): NumberBadge {
            badgeDrawable.enableBadgeText()
            return NumberBadge(badgeDrawable, anchor, gravity)
        }

    }

}